package archer.application.core.entity.user;

import archer.application.core.constant.Constant;
import archer.framework.common.entity.BaseEntity;
import com.avaje.ebean.annotation.Encrypted;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp;

/**
 * @author christ
 * @date 2016/6/3
 */
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", columnDefinition = "varchar(30) COMMENT '类型'", length = 30)
public class User extends BaseEntity {

    public static final Find<User> find = new Find<User>(User.class);

    /**
     * 登录名
     */
    @Column(columnDefinition = "varchar(30) COMMENT '登陆名称'")
    @Length(max = 30, message = "登录名长度非法")
    private String loginName;

    /**
     * 手机号
     */
    @Column(columnDefinition = "varchar(30) COMMENT '手机号'")
    @Length(max = 30, message = "手机号长度非法")
    private String mobile;

    /**
     * 邮箱
     */
    @Column(columnDefinition = "varchar(30) COMMENT '邮箱'")
    @Length(max = 30, message = "邮箱长度非法")
    private String email;

    /**
     * 备注
     */
    @Length(max = 255, message = "备注长度非法")
    private String remark;

    @Transient
    private String type;
    /**
     * 密码
     */
    @NotNull(message = "密码不能为空")
    @Encrypted
    private String password;

    @Column(columnDefinition = "varchar(50) COMMENT '登陆用户类型'")
    private String status = Constant.UserStatus.ENABLE;

    /**
     * 最近一次登录时间
     */
    private Timestamp lastLoginTime;

    public String getLoginName() {
        return loginName;
    }

    public User setLoginName(String loginName) {
        this.loginName = loginName;
        return this;
    }

    public String getMobile() {
        return mobile;
    }

    public User setMobile(String mobile) {
        this.mobile = mobile;
        return this;
    }

    public String getEmail() {
        return email;
    }

    public User setEmail(String email) {
        this.email = email;
        return this;
    }

    public String getRemark() {
        return remark;
    }

    public User setRemark(String remark) {
        this.remark = remark;
        return this;
    }

    public String getPassword() {
        return password;
    }

    public User setPassword(String password) {
        this.password = password;
        return this;
    }

    public String getStatus() {
        return status;
    }

    public User setStatus(String status) {
        this.status = status;
        return this;
    }

    public String getType() {
        return type;
    }

    public User setType(String type) {
        this.type = type;
        return this;
    }

    public Timestamp getLastLoginTime() {
        return lastLoginTime;
    }

    public User setLastLoginTime(Timestamp lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
        return this;
    }
}
